<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>课程详情</title>
    <link rel="stylesheet" type="text/css" href="__CSS__api.css"/>
    <link rel="stylesheet" type="text/css" href="__CSS__aui.css"/>
    <link rel="stylesheet" type="text/css" href="__CSS__video-js.min.css"/>
    <style>
        .vedio {
            position: relative;
            width: 100%;
            height: 10.45rem;
            overflow: hidden;
        }

        .mask {
            position: absolute;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            line-height: 10.45rem;
            text-align: center;
            font-size: 1rem;
        }

        .instruction {
            background-color: #fff;
            padding: 0.75rem;
            padding-bottom: 0;
            margin-bottom: 0.5rem;
        }

        .title {
            font-weight: bold;
            font-size: 0.75rem;
            color: #333;
        }

        .play_times {
            font-size: 0.75rem;
            color: #999;
        }

        .like, .share, .download {
            float: right;
            width: 1.5rem;
            height: 1.5rem;
            margin-left: 1rem;
        }

        .play_all {
            height: 30px;
            line-height: 30px;
        }

        .download {
            background: url(__IMG__main3_download.png) no-repeat center center;
            background-size: 22px 22px;
        }

        .share {
            width: 22px;
            height: 22px;
            background: url(__IMG__main3_share.png) no-repeat center center;
            background-size: 22px 22px;
        }

        .like img {
            width: 22px;
            height: 22px;
            margin: 4px auto;
        }

        .class_type {
            line-height: 2.5rem;
            margin-top: 0.5rem;
        }

        .course_type {
            color: #999;
            font-size: 0.75rem;
        }

        .type_detail {
            color: #4FBF04;
            font-size: 0.7rem;
            float: right;
        }

        /*价格 红色字体*/
        .money {
            font-size: 0.7rem;
            color: #FE0030;
            float: right;
        }

        /*tab*/
        .aui-bar-nav .aui-pull-right {
            padding-right: 0.75rem;
        }

        .aui-tab-item.aui-active {
            color: #E73C5C;
            font-weight: bold;
            font-size: 0.8rem;
            border: 0;
        }

        .aui-active:after {
            content: '';
            display: block;
            height: 0px;
            width: 100%;
            border-top: 2px solid #E73C5C;
            bottom: 0px;
            position: absolute;
        }

        .fenlei {
            width: 4.2rem;
            margin-left: 0.75rem;
            display: box;
        }

        .juzhon1 {
            width: 100%;
            height: 1.25rem;
            line-height: 1rem;
            text-align: center;
            font-size: 11px;
        }

        .sss {
            margin: 0px 15px;
            width: 100%;
        }

        .aui-tab-item {
            height: 2.4rem;
            line-height: 2.4rem;
            font-size: 0.8rem;
            color: #333;
        }

        #my-player {
            position: relative;
            width: 100%;
            height: 10.45rem
        }

        .stop-button {
            position: absolute;
            top: 40%;
            left: 50%;
            -webkit-transform: translate(-50%);
            transform: translate(-50%);
            width: 42px;
            height: 42px;
            background: url("__IMG__main3_stop.png") center center no-repeat;
            background-size: 42px;
        }

        .play-button {
            position: absolute;
            top: 40%;
            left: 50%;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
            width: 42px;
            height: 42px;
            background: url("__IMG__main3_play.png") center center no-repeat;
            background-size: 42px;
        }

        .lock-button {
            position: absolute;
            top: 40%;
            left: 10%;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
            width: 42px;
            height: 42px;
            background: url("__IMG__main3_lock.png") center center no-repeat;
            background-size: 42px;
        }

        .unlock-button {
            position: absolute;
            top: 40%;
            left: 10%;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
            width: 42px;
            height: 42px;
            background: url("__IMG__main3_unlock.png") center center no-repeat;
            background-size: 42px;
        }

        .vjs-default-skin .vjs-big-play-button {
            display: none
        }

        .video-js .vjs-time-control {
            display: block;
        }

        .video-js .vjs-remaining-time {
            display: none;
        }

        .vjs-default-skin.vjs-big-play-centered .vjs-big-play-button {
            display: none;
        }

        .video-js .vjs-big-play-button {
            display: none !important;

        }

        .video-js .vjs-big-play-button {
            font-size: 2.5em;
            line-height: 2.3em;
            height: 2.5em;
            width: 2.5em;
            -webkit-border-radius: 2.5em;
            -moz-border-radius: 2.5em;
            border-radius: 2.5em;
            background-color: #73859f;
            background-color: rgba(115, 133, 159, .5);
            border-width: 0.15em;
            margin-top: -1.25em;
            margin-left: -1.75em;
        }

        /* 中间的播放箭头 */
        .vjs-big-play-button .vjs-icon-placeholder {
            font-size: 1.63em;
        }

        /* 加载圆圈 */
        .vjs-loading-spinner {
            font-size: 2.5em;
            width: 2em;
            height: 2em;
            border-radius: 1em;
            margin-top: -1em;
            margin-left: -1.5em;
        }
    </style>
</head>

<body>
<div id="all_header">
    <div class="vedio before">
        <video id="my-player"
               class="video-js vjs-big-play-centered"
               controls
               poster="__IMG__zhanweitu/main3_video.png"
               preload="load"
               webkit-playsinline="true"
               allowfullscreen="true"
               webkitallowfullscreen="true"
               mozallowfullscreen="true"
               webkit-playsinline="true"
               playsinline="true"
               x5-video-player-type="h5"
               x5-video-player-fullscreen="true"
               x-webkit-airplay="allow"
               x5-video-orientation="portraint"
               data-setup='{"example_option":true}'
               style="width: 100%"
        >
            <source src="__IMG__zhanweitu/black.mp4" type="video/mp4"/>
            <p class="vjs-no-js">
                请开启Javascript脚本以便
                <a href="http://videojs.com/html5-video-support/" target="_blank">
                    支持HTML5 video播放器
                </a>
            </p>
        </video>
    </div>
    <input type="hidden" name="classroom_id" value="{$classroom_id}">
    <input type="hidden" name="classroom_cate" value="{$classroom_cate}">
    <div id="render-item-1"></div>
    <div class="aui-tab bar underLine">
        <div class="underLine sss aui-tab bar nav" id="tab">
            <div class="aui-tab-item aui-active">详情</div>
            <div class="aui-tab-item">目录</div>
        </div>
    </div>
</div>
</body>
<script type="text/x-handlebars-template" id="template-item-1">
    <div class="instruction">
        <div class="aui-ellipsis-2 title" id='getInformation' a_id='{{=it.id}}'>{{=it.classroom_title}}</div>
        <div class="play_all">
            <span class="play_times">播放：{{=it.classroom_playnum}}次</span>
            <span class="download" tapmode onclick="download()"></span>
            <span class="share" tapmode onclick="share()"></span>
            {{?it.collection==1}}
            <span class="like"><img src="__IMG__main3_like.png" data-type="1" tapmode
                                    onclick="toggleCollect(this)"></span>
            {{??}}
            <span class="like"><img src="__IMG__main3_unlike.png" data-type="2" tapmode
                                    onclick="toggleCollect(this)"></span>
            {{?}}
        </div>
        {{?api.pageParam.type==1&&$api.getStorage('price_button')==1}}
        <div class="class_type topLine2"><span class="course_type">课程类型</span><span class="type_detail">免费</span></div>
        {{??}}
        <div class="class_type topLine2"><span class="course_type">课程类型</span><span class="money">¥{{=it.classroom_price}}</span>
        </div>
        {{?}}
    </div>
</script>
<script type="text/javascript" src="__JS__jquery.min.js"></script>
<script type="text/javascript" src="__JS__api.js"></script>
<script type="text/javascript" src="__JS__tt.js"></script>
<script type="text/javascript" src="__JS__aui-tab.js"></script>
<script type="text/javascript" src="__JS__doT.min.js"></script>
<script type="text/javascript">
    var classroom_cate;//课程类型   1 免费课程 2 付费课程
    var classroom_id;//课程ID
    var catalogue_id = '';//目录ID
    var video_url;//视频下载地址
    var video_name;//视频下载名称
    var myPlayer;//videojs
    var buttonGroup = [
        '',
        '',
        ''];//按钮组,返回,暂停,播放
    var isPlay = true;
    var UIButton;//按钮
    var videoData;
    apiready = function () {
        classroom_cate = $('input[name="classroom_cate"]');
        classroom_id = $('input[name="classroom_id"]');
        initData();

        changeVideo();
    };

    //设置头样式
    function silcIndex(index) {
        var tab = new auiTab({
            element: document.getElementById('tab'),
            index: index + 1
        }, function (ret, index) {
        });
    }

    //动态加载
    function dynamicLoadJs(url, callback) {
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url;
        if (typeof(callback) == 'function') {
            script.onload = script.onreadystatechange = function () {
                if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
                    callback();
                    script.onload = script.onreadystatechange = null;
                }
            };
        }
        head.appendChild(script);
    }

    //播放器上的按钮
    function stopAndPlay(el) {

        if (el.className == 'play-button') {
            el.className = 'stop-button';
            myPlayer.play();
        } else if (el.className == 'stop-button') {
            el.className = 'play-button';
            myPlayer.pause();
        } else if (el.className == 'lock-button') {
            el.className = 'unlock-button';
            $api.dom('.vjs-control-bar').style.visibility = 'visible';

        } else if (el.className == 'unlock-button') {
            el.className = 'lock-button';
            $api.dom('.vjs-control-bar').style.visibility = 'hidden';
        }
    }

    //播放器
    function play(url) {
        dynamicLoadJs('__JS__video.min.js', function () {
            myPlayer = videojs('my-player');
            myPlayer.src(url);
            videojs('my-player').ready(function () {
                this.play();
                $api.append($api.byId('my-player'), '<div class=\'stop-button\' id="btn-change" onclick="stopAndPlay(this)"></div>');
            });
            myPlayer.on('fullscreenchange', function () {
                console.log(JSON.stringify(api));
                if (this.isFullscreen()) {
                    $api.byId('btn-change').className = 'unlock-button';
                } else {
                    $api.byId('btn-change').className = 'stop-button';

                }
            });
            myPlayer.on('useractive', function () {
                console.log('Play useractive');
                if (!this.isFullscreen()) {
                    $api.byId('btn-change').style.display = 'block';
                } else {
                    $api.byId('btn-change').style.display = 'block';
                }
            });
            myPlayer.on('userinactive', function () {
                console.log('Play userinactive');
                setTimeout(function () {
                    if ($api.byId('btn-change').className == 'play-button') {
                        return;
                    }
                    if (!myPlayer.isFullscreen()) {
                        $api.byId('btn-change').style.display = 'none';
                    } else {
                        if ($api.byId('btn-change').className == 'unlock-button') {
                            if (isPlay) {
                                setTimeout(function () {
                                    $api.byId('btn-change').style.display = 'none';
                                }, 300);
                            }
                        }
                    }
                }, 300);
            });
            myPlayer.on('pause', function () {
                console.log('Play pause');
                isPlay = false;
                if (!this.isFullscreen()) {
                    $api.byId('btn-change').className = 'play-button';
                }
            });
            myPlayer.on('play', function () {
                console.log('Play play');
                isPlay = true;
                if (!this.isFullscreen()) {
                    $api.byId('btn-change').className = 'stop-button';
                }
            });
        });
    }

    //初始化
    function initData() {
        $.ajax({
            url: '{:url("Classroom/classroomInfo")}',
            data: {classroom_cate: classroom_cate, classroom_id: classroom_id},
            type: 'POST',
            dataType: 'json',
            success:function (data) {
                if (data.status == 200) {
                    var temp = doT.template($api.byId('template-item-1').innerHTML);
                    $api.html($api.byId('render-item-1'), temp(successData.data));
                    video_name = successData.data.classroom_title;
                    if ($api.dom('.mask')) {
                        $api.dom('.mask').style.display = 'none';
                    }
                    initData2();
                    updataHistory();
                    fnChange(0, true);
                    var tab = new auiTab({
                        element: document.getElementById('tab'),
                        index: 1
                    }, function (ret) {
                        oncilck(ret.index - 1);
                        console.log(ret.index);
                    });
                } else {
                    fnChange(0, false);
                    var tab = new auiTab({
                        element: document.getElementById('tab'),
                        index: 1
                    }, function (ret) {
                        oncilck(ret.index - 1);
                        console.log(ret.index);
                    });
                    dynamicLoadJs('__JS__video.min.js', function () {
                        myPlayer = videojs('my-player');
                        videojs('my-player').ready(function () {
                            $api.append($api.byId('my-player'), '<div class=\'mask\'>请购买课程</div>');
                        });
                    });
                }
            }
        }),function (err) {

        }
    }

    //播放地址
    function initData2() {
        $.ajax({
            url: '{:url("Classroom/videoUrl")}',
            data: {catalogue_id: catalogue_id, classroom_id: classroom_id},
            type: 'POST',
            dataType: 'json',
            success:function (data) {
                if (data.status == 200) {
                    catalogue_id = data.catalogue_id;
                    video_url = data.catalogue_url;
                    play(data.catalogue_url);
                } else {
                    alert(data.msg);
                }
            }
        });
    }

    //收藏与取消收藏
    function toggleCollect(el) {
        var type = $api.attr(el, 'data-type');
        if (type == 1) {
            $.ajax({
                url: '{:url("Classroom/myCollect")}',
                data: {catalogue_id: catalogue_id, classroom_id: classroom_id},
                type: 'POST',
                dataType: 'json',
                success:function (data) {
                    if (successData.status == '200') {
                        el.src = '__IMG__main3_unlike.png';
                        $api.attr(el, 'data-type', '2');
                    }
                }
            })
        } else {
            $.ajax({
                url: '{:url("Classroom/myCollect")}',
                data: {catalogue_id: catalogue_id, classroom_id: classroom_id},
                type: 'POST',
                dataType: 'json',
                success:function (data) {
                    if (successData.status == '200') {
                        el.src = '__IMG__main3_like.png';
                        $api.attr(el, 'data-type', '1');
                    }
                }
            })
        }
    }

    //更新查看历史
    function updataHistory() {
        $.ajax({
            url: '{:url("Classroom/history")}',
            data: {catalogue_id: catalogue_id, classroom_id: classroom_id},
            type: 'POST',
            dataType: 'json',
            success:function (data) {
            }
        })
    }

    //根据目录更换播放源
    function changeVideo() {
        $.ajax({
            url:'{:url("Classroom/classroomInfo")}',
            data:{classroom_cate: classroom_cate, classroom_id: classroom_id},
            type:'POST',
            dataType:'json',
            success:function(res){
                if(res.status == 200){
                    var temp = doT.template($api.byId('template-item-1').innerHTML);
                    $api.html($api.byId('render-item-1'), temp(res.data));
                    video_name = res.data.classroom_title;

                    $.ajax({
                        url: '{:url("Classroom/videoUrl")}',
                        data: {catalogue_id: catalogue_id, classroom_id: classroom_id},
                        type: 'POST',
                        dataType: 'json',
                        success:function (successData) {
                            if (data.status == 200) {
                                catalogue_id = successData.data.catalogue_id;
                                video_url = successData.data.catalogue_url;
                                videoData = successData.data;
                                if (myPlayer.src != video_url) {
                                    myPlayer.src(video_url);
                                    myPlayer.load();
                                    myPlayer.play();
                                    button();
                                    updataHistory();
                                } else {
                                    alert('正在播放中');
                                }
                            } else {
                                alert(successData.msg);
                            }
                        }
                    });

                }else{
                    alert(res.msg)
                }
            }
        })
    }

    //购买以后渲染页面
    function buyInitData() {
        var parame = {
            values: {
                classroom_cate: classroom_cate,
                classroom_id: classroom_id
            }
        };
        doAjax(CLASSROOMINFO, 'POST', parame, function (successData) {
            if (successData.status == '200') {
                var temp = doT.template($api.byId('template-item-1').innerHTML);
                $api.html($api.byId('render-item-1'), temp(successData.data));
                video_name = successData.data.classroom_title;
                if ($api.dom('.mask')) {
                    $api.dom('.mask').style.display = 'none';
                }
                var header = $api.byId('all_header');
                var headerH = $api.offset(header).h;
                api.setFrameGroupAttr({
                    name: 'main3_details_frm',
                    rect: {
                        x: 0,
                        y: headerH,
                        w: 'auto',
                        h: 'auto'
                    }
                });
                updataHistory();
                console.log(api.pageParam.type);
                if (api.pageParam.type == 2) {
                    var jsfun = 'isBuy();';
                    api.execScript({
                        frameName: 'main3_details_frm0',
                        script: jsfun
                    });
                }
            } else {
                api.toast({
                    msg: successData.msg,
                    duration: 2000,
                    location: 'middle'
                });
                dynamicLoadJs('__JS__video.min.js', function () {
                    myPlayer = videojs('my-player');
                    videojs('my-player').ready(function () {
                        $api.append($api.byId('my-player'), '<div class=\'mask\'>请购买课程</div>');
                    });
                });
            }

            button();
        });
    }

    //右上角返回按钮
    function button() {

    }

    //显示当前可见frame
    function oncilck(index) {

    }

    function fnChange(index, isBuy) {

    }


</script>
</html>
